﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace CMS
{
    [Serializable]
    public class Permission
    {

        public long? ADM_ID { get; set; }
        public long? PERM_ID { get; set; }
        public long? USR_ID { get; set; }
        public Boolean USR  { get; set; }
        public Boolean UPL { get; set; }
        public Boolean PAG { get; set; }
        public Boolean HRS { get; set; }
        public string PERM_NAME { get; set; }

        #region Constructors
        /// <summary>
        /// Creates a new instance of an Page object.
        /// </summary>
        public Permission() : this(null) { }

        /// <summary>
        /// Creates a new instance of an Page object.
        /// </summary>
        public Permission(long? id)
        {
            PERM_ID = id;
        }
        #endregion

        /// <summary>
        /// Returns a list of Pages.
        /// </summary>
        public static List<CMS.Permission> GetPermission(Int64? ADM_ID, Int64? PERM_ID, Int64? USR_ID, Boolean? UPL, Boolean? USR, Boolean? PAG, Boolean? HRS, String PERM_NAME)
        {
            DataTable StoredProcedureTablePages = CMS.StoredProcedureValues.VW_Permissions(ADM_ID, PERM_ID, USR_ID, UPL, USR, PAG,HRS, PERM_NAME);
            return GetListPermission(StoredProcedureTablePages);
        }

        /// <summary>
        /// Converts a DataTable into a list of Pages.
        /// </summary>
        public static List<CMS.Permission> GetListPermission(DataTable StoredProcedureTable)
        {
            List<CMS.Permission> OutPermission = new List<CMS.Permission>();

            for (int i = 0; i < StoredProcedureTable.Rows.Count; i++)
            {
                CMS.Permission Permission = new CMS.Permission();
                DataRow Row = StoredProcedureTable.Rows[i];

                Permission.ADM_ID = Convert.ToInt64((Row["ADM_ID"]));
                Permission.PERM_ID = Convert.ToInt64((Row["PERM_ID"]));
                Permission.USR_ID = Convert.ToInt64((Row["USR_ID"]));
                Permission.UPL = Convert.ToBoolean(Row["UPL"].ToString());
                Permission.USR = Convert.ToBoolean(Row["USR"].ToString());
                Permission.PAG = Convert.ToBoolean(Row["PAG"].ToString());
                Permission.HRS = Convert.ToBoolean(Row["HRS"].ToString());
                Permission.PERM_NAME = Row["PERM_NAME"].ToString();

                OutPermission.Add(Permission);
            }

            return OutPermission;
        }
    }
}